﻿#include<stdio.h>
#include<stdlib.h>
#define N 40
void Readscore(struct STUDENT stu[], int n);
int Add(struct STUDENT stu[], int n);
int Aver(struct STUDENT stu[], int n);
void Ascendingsort(struct STUDENT stu[], int m);
void descendingsort(struct STUDENT stu[], int m);
void printfscore(struct STUDENT stu[], int m);
void printOnefscore(struct STUDENT stu[], int a);
struct Date
{
	int year;
	int month;
	int day;
};
struct STUDENT
{
	int ID;
	char Name[10];
	char Sex;
	struct Date birthday;
	int score[6];
};
int main()
{
	int m;//人数
	int n;//执行符号
	int a;//搜索学号
	struct STUDENT stu[N];
	struct Date;
	printf("1.输入学号,姓名，性别，生日和四科成绩\n2.计算总分和平均分\n3.降序排列\n4.升序排列\n5.搜索成绩\n6.打印所有成绩\n0.退出\n");
	do
	{
		printf("\n");
		printf("n=");
		scanf("%d", &n);
		if (n == 1)
		{
			printf("有多少学生？");
			scanf("%d", &m);
			Readscore(stu, m);
		}
		else if (n == 2)
		{
			Add(stu, m);
			Aver(stu, m);
		}
		else if (n == 3)
		{
			descendingsort(stu, m);
		}
		else if (n == 4)
		{
			Ascendingsort(stu, m);
		}
		else if (n == 5)
		{
			printf("输入学生`排名i：");//先搜索学生排名 以后升级的时候再改学号吧
			scanf("%d", &a);
			printOnefscore(stu, a);
		}
		else if (n == 6)
		{
			printfscore(stu, m);
		}

	} while (n != 0);
	fflush(stdin);
	system("pause");
	return 0;
}
void Readscore(struct STUDENT stu[], int n)
{
	int i, j;
	printf("\t学号  姓名 性别 生日\t四科成绩\n");
	for (i = 0; i < n; i++)
	{
		printf("学生%d：", i + 1);
		scanf("%ld", &stu[i].ID);
		scanf("%s", &stu[i].Name);
		scanf(" %c", &stu[i].Sex);
		scanf("%ld", &stu[i].birthday.year);
		scanf("%ld", &stu[i].birthday.month);
		scanf("%ld", &stu[i].birthday.day);
		for (j = 0; j <= 3; j++)
		{
			scanf("%ld", &stu[i].score[j]);
		}
		fflush(stdin);
	}
}
int Add(struct STUDENT stu[], int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		stu[i].score[4] = stu[i].score[1] + stu[i].score[2] + stu[i].score[3] + stu[i].score[0];
		printf("学生%d的总分=%d   ", i + 1, stu[i].score[4]);
	}
	printf("\n");
	return stu[i].score[4];
}
int Aver(struct STUDENT stu[], int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		stu[i].score[5] = stu[i].score[4] / 4;
		printf("学生%d的平均分=%d  ", i + 1, stu[i].score[5]);
	}
	printf("\n");
	return stu[i].score[5];
}
void Ascendingsort(struct STUDENT stu[], int m)//升序
{
	int i, j, k;
	for (i = 0; i < m; i++)
	{
		j = i;
		stu[j] = stu[i];
		for (k = j + 1; k < m; k++)
		{
			if (stu[i].score[5]>stu[k].score[5])
			{
				stu[m + 1] = stu[k];
				stu[k] = stu[j];
				stu[j] = stu[m + 1];
			}
		}
	}
}
void descendingsort(struct STUDENT stu[], int m)//降序
{
	int i, j, k;
	for (i = 0; i < m; i++)
	{
		j = i;
		stu[j] = stu[i];
		for (k = j + 1; k < m; k++)
		{
			if (stu[i].score[5]<stu[k].score[5])
			{
				stu[m + 1] = stu[k];
				stu[k] = stu[j];
				stu[j] = stu[m + 1];
			}
		}
	}
}
void printOnefscore(struct STUDENT stu[], int a)//打印一只学生
{
	int j;
	a = a - 1;
	printf("学生%d的ID：%d\t", a + 1, stu[a].ID);
	printf("学生%s的姓名：%s\t", a + 1, stu[a].Name);
	printf("学生%c的性别=%s\t", a + 1, stu[a].Sex);
	printf("学生%d的生日：%d.%d.%d\t", a + 1, stu[a].birthday.year, stu[a].birthday.month, stu[a].birthday.day);
	printf("学生%d的 四科成绩 总成绩 平均成绩 分别为：", a + 1);
	for (j = 0; j <= 5; j++)//调试改动过
	{
		printf("%d ", stu[a].score[j]);
	}
	printf("\n");
}
void printfscore(struct STUDENT stu[], int m)//打印很多只学生
{
	int i, j;
	for (i = 0; i < m; i++)
	{
		printf("学生%d ID：%d\t", i + 1, stu[i].ID);
		printf("姓名：%s\t", stu[i].Name);
		printf("性别:%c\t", stu[i].Sex);
		printf("生日：%d.%d.%d\t", stu[i].birthday.year, stu[i].birthday.month, stu[i].birthday.day);
		printf("四科成绩 总成绩 平均成绩 分别为：");
		for (j = 0; j <= 5; j++)//调试改动过
		{
			printf("%d ", stu[i].score[j]);
		}
		printf("\n");
	}
}

/*简化函数升序和降序的日后再写进去
int Ascendingsort(int a, int b);
int Ascendingsort(int a,int b)
{
return a > b;
}


int descendingsort(int a, int b);
int descendingsort(int a, int b)
{
return a < b;


}*/
/*
void Swap(struct STUDENT stu[],int a,int b,int c)//单独写个交换函数太复杂感觉没这个必要
{
stu[m+1] = stu[k];
stu[k] = stu[j];
stu[j] = stu[m+1];
}


void Swap(struct STUDENT stu[],int a,int b,int c);
*/

